// hyb_yl/czhuanjiasubpages/pages/longsevers/index.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    region: ["四川省", "广元市", "苍溪县"],
    items: [{
        id:0,
        name: '明确诊断',
        value: '明确诊断',
        checked: false
      },
      {
        id:1,
        name: '请专家给治疗方案，开处方',
        value: '请专家给治疗方案，开处方',
        checked: false
      },
      {
        id:2,
        name: '咨询手术',
        value: '咨询手术',
        checked: false
      },
      {
        id:3,
        name: '转诊沟通',
        value: '转诊沟通',
        checked: false
      }
    ],
    itemsIndex:0,
    citems: [{
        name: '在住院治疗',
        value: '在住院治疗',
        radiocheck:false,
      },
      {
        name: '没有住院',
        value: '没有住院',
        radiocheck: false,
      }
    ],
    one_key: false,
    mask_key: false,
  },
  
  //地区选择器
  changeRegin(e) {
    this.setData({
      region: e.detail.value
    });
  },
  //多选框
  checkboxChange: function(e) {
    console.log(e.detail.value)
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
    var items = this.data.items;
    var id = [];
    // 获取标签id
    for (var i = 0; i < e.detail.value.length; i++) {
      var idNum =e.detail.value[i].split(',');
      console.log(idNum)
      id = id.concat(idNum[1])
    }
    console.log(id)
    for (var y = 0; y < items.length; y++) {
      if (id.indexOf(y + "") != -1) {
        items[y].checked = true;
      } else {
        items[y].checked = false;
      }
    }
    this.setData({
      items: items
    });
  },
  choseque:function(e){
    console.log(e)
  },
  //单选框
  radioChange: function(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    var citems = this.data.citems;
    this.setData({
      sex: e.detail.value
    })
    var citems = this.data.citems;
    for (var i = 0; i < citems.length; ++i) {
      citems[i].checked = citems[i].value == e.detail.value
    }
    console.log(citems)
    this.setData({
      citems: citems
    });
  },
  choseradio: function(e) {
    let index = e.currentTarget.dataset.index
    if (index == 0) {
      this.setData({
        one_key: true
      })
    } else {
      this.setData({
        one_key: false
      })
    }
  },
  //获取数据
  submit: function(e) {
    console.log(e, 1111)
    var that = this
    var arr =[]
   var hopesove = e.detail.value.hopesove
    for(var i= 0;i<hopesove.length;i++){
      var a = hopesove[i].split(',');
      arr = arr.concat(a[0])
    }
    console.log(arr)
    var tel = that.data.tel
    var names = that.data.names
    var city = e.detail.value.city
    var sickname = e.detail.value.sickname
    // var hopesove = e.detail.value.hopesove.join("　")
    var hopesove = arr.join("　")
    var ishospit = e.detail.value.ishospit
    var hospitname = e.detail.value.hospitname
    var docname = e.detail.value.docname
    var zid = that.data.zid
    var j_id = that.data.j_id
    var keywords = that.data.keywords
    if (ishospit == "在住院治疗") {
      var mesage = [{
          question: '患者姓名',
          ansers: names
        },
        {
          question: '联系方式',
          ansers: tel
        },
        {
          question: '所患疾病',
          ansers: sickname
        },
        {
          question: '所在城市',
          ansers: city
        },
        {
          question: '希望解决什么问题？',
          ansers: hopesove
        },
        {
          question: '患者是否在住院治疗？',
          ansers: ishospit
        },
        {
          question: '所住医院信息',
          ansers: hospitname,
        },
        {
          question: '所患疾病',
          ansers: docname
        },
      ]
    } else {
      var mesage = [{
          question: '患者姓名',
          ansers: names
        },
        {
          question: '联系方式',
          ansers: tel
        },
        {
          question: '所患疾病',
          ansers: sickname
        },
        {
          question: '所在城市',
          ansers: city
        },
        {
          question: '希望解决什么问题？',
          ansers: hopesove
        },
        {
          question: '患者是否在住院治疗？',
          ansers: ishospit
        }
      ]
    }
    app.util.request({
      'url': 'entry/wxapp/Hzbingli.addbingli',
      data: {
        msglist: mesage,
        sicktel: that.data.tel,
        openid: wx.getStorageSync('openid'),
        j_id: j_id,
        keywords: keywords
      },
      success: function(res) {
        console.log(res)
        var bl_id = res.data
        //插入问诊订单
        var name = that.data.name
        app.util.request({
          'url': 'entry/wxapp/Hzbingli.addorder',
          data: {
            zid: that.data.zid,
            name: name,
            keywords: keywords,
            openid: wx.getStorageSync('openid'),
            bl_id: bl_id,
            money: that.data.newmoney,
            j_id: j_id
          },
          success: function(res) {
            console.log(res)
            var name = res.data.name
            var order = res.data.order
            var money = that.data.newmoney
            var oid = res.data.oid
            wx.navigateTo({
              url: '/hyb_yl/czhuanjiasubpages/pages/questends/index?phone=' + that.data.tel + '&zid=' + zid + '&name=' + name + '&keywords=' + keywords + '&j_id=' + j_id + '&allone_key=1' + '&name=' + name + '&order=' + order + '&money=' + money + '&oid=' + oid + '&bl_id=' + bl_id
            })
          }
        })
      }
    })
  },
  //去支付
  alipay: function() {
    // wx.navigateTo({
    //   url: '/hyb_yl/czhuanjiasubpages/pages/questends/index'
    // })
  },
  close: function() {
    this.setData({
      mask_key: false
    })
  },
  //下一个页面
  nextpage: function(e) {
    let index = e.currentTarget.dataset.index
    if (index == 0) {

    } else if (index == 1) {
      wx.navigateTo({
        url: '/hyb_yl/czhuanjiasubpages/pages/questends/index'
      })
    }

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var zid = options.zid
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var keywords = options.keywords
    var name = options.name
    var money = options.money
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.docinfo',
      data: {
        zid: zid,
        key: keywords,
      },
      success: function(res) {
        that.setData({
          newmoney: res.data.data.newmoney
        })
      }
    })
    that.setData({
      zid: zid,
      keywords: keywords,
      name: name,
      bgc: bgc
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function(e) {
    var that = this
    let pages = getCurrentPages();
    let currPage = pages[pages.length - 1];
    if (currPage.data.names) {
      that.setData({ //将携带的参数赋值
        names: currPage.data.names
      });
    }
    if (currPage.data.j_id) {
      that.setData({ //将携带的参数赋值
        j_id: currPage.data.j_id
      });
    }
    if (currPage.data.tel) {
      that.setData({ //将携带的参数赋值
        tel: currPage.data.tel
      });
    }
    if (currPage.data.region && currPage.data.state == 1) {
      that.setData({ //将携带的参数赋值
        region: currPage.data.region
      });
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  selhuanzhe() {
    // zid = 54 & name=电话问诊 & keywords=dianhuawenzhen & j_id=2
    var that = this
    var zid = that.data.zid
    var name = that.data.name
    var keywords = that.data.keywords
    var j_id = that.data.j_id
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?zid=' + zid + '&name=' + name + '&keywords=' + keywords + '&j_id=' + j_id,
    })
  }
})